package com.github.camera;

import android.app.Activity;
import android.content.Intent;

import com.github.camera.utils.DoubleUtils;

import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.List;

public class PictureSelector implements Serializable {

    private final WeakReference<Activity> reference;

    private PictureSelector(Activity activity) {
        reference = new WeakReference<>(activity);
    }

    public static PictureSelector build(Activity activity) {
        PictureConfig.getInstance().reset();
        return new PictureSelector(activity);
    }

    public PictureSelector takePhotoModel(int takePhotoModel) {
        PictureConfig.getInstance().setTakePhotoModel(takePhotoModel);
        return this;
    }

    public PictureSelector enableCrop(boolean enableCrop) {
        PictureConfig.getInstance().setEnableCrop(enableCrop);
        return this;
    }

    public PictureSelector openLight(boolean openLight) {
        PictureConfig.getInstance().setOpenLight(openLight);
        return this;
    }

    public PictureSelector cameraType(int cameraType) {
        PictureConfig.getInstance().setCameraType(cameraType);
        return this;
    }

    //多张连拍
    public PictureSelector photoList(List<PictureModel> photolist) {
        PictureConfig.getInstance().setPhotoList(photolist);
        return this;
    }

    public PictureSelector enableAlbum(boolean enableAlbum) {
        PictureConfig.getInstance().setEnableAlbum(enableAlbum);
        return this;
    }

    public void builder(int requestCode) {
        if (DoubleUtils.isFastDoubleClick()) {
            return;
        }
        if (reference.get() == null) {
            return;
        }
        Intent intent = new Intent(reference.get(), CameraActivity.class);
        if (reference.get() != null) {
            reference.get().startActivityForResult(intent, requestCode);
        }
    }


}
